package com.kye.express.business.jd.goods_list_by_category.model;

import android.os.Parcel;
import android.os.Parcelable;

import com.kye.model.bean.jd.shop.JDGoodsCategoryBean;

/**
 * @author : Joe
 * @version : 1.0
 * @editor : Joe
 * @created : 29/01/2018
 * @updated : 29/01/2018
 * @description : <Description>
 * @update_reason : <UpdateReason>
 */

public class JDCategoryTagModel implements Parcelable {

    private JDGoodsCategoryBean goodsCategoryBean;
    private boolean isSelected;

    public boolean isSelected() {
        return isSelected;
    }

    public void setSelected(boolean selected) {
        isSelected = selected;
    }

    public JDGoodsCategoryBean getGoodsCategoryBean() {
        return goodsCategoryBean;
    }

    public void setGoodsCategoryBean(JDGoodsCategoryBean goodsCategoryBean) {
        this.goodsCategoryBean = goodsCategoryBean;
    }

    public JDCategoryTagModel() {
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeParcelable(this.goodsCategoryBean, flags);
        dest.writeByte(this.isSelected ? (byte) 1 : (byte) 0);
    }

    protected JDCategoryTagModel(Parcel in) {
        this.goodsCategoryBean = in.readParcelable(JDGoodsCategoryBean.class.getClassLoader());
        this.isSelected = in.readByte() != 0;
    }

    public static final Creator<JDCategoryTagModel> CREATOR = new Creator<JDCategoryTagModel>() {
        @Override
        public JDCategoryTagModel createFromParcel(Parcel source) {
            return new JDCategoryTagModel(source);
        }

        @Override
        public JDCategoryTagModel[] newArray(int size) {
            return new JDCategoryTagModel[size];
        }
    };

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof JDCategoryTagModel)) return false;

        JDCategoryTagModel that = (JDCategoryTagModel) o;

        if (isSelected != that.isSelected) return false;
        return goodsCategoryBean.equals(that.goodsCategoryBean);
    }

    @Override
    public int hashCode() {
        int result = goodsCategoryBean.hashCode();
        result = 31 * result + (isSelected ? 1 : 0);
        return result;
    }
}
